import random


class RandomizedSet:

    def __init__(self):
        self.data = []
        self.data_index = {}

    def insert(self, val: int) -> bool:
        """
        Inserts a value to the set. Returns true if the set did not already contain the specified element.
        """
        if val in self.data_index:
            return False
        self.data.append(val)
        self.data_index[val] = len(self.data) - 1
        return True

    def remove(self, val: int) -> bool:
        """
        Removes a value from the set. Returns true if the set contained the specified element.
        """
        if val in self.data_index:
            idx, last_val = self.data_index[val], self.data[-1]
            self.data[idx], self.data_index[last_val] = last_val, idx
            self.data.pop()
            self.data_index.pop(val)
            return True
        return False

    def getRandom(self) -> int:
        """
        Get a random element from the set.
        """
        return random.choice(self.data)
